package com.yaozheng.vocationaltraining.service.impl;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.ITokenBaseView;
import com.yaozheng.vocationaltraining.iview.integral.IMyIntegralView;
import com.yaozheng.vocationaltraining.service.MyIntegralService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

/**
 * 我积分
 *
 * @author Administrator
 */
@EBean
public class MyIntegralServiceImpl implements MyIntegralService {
    IMyIntegralView iMyIntegralView;

    @Override
    public void init(IMyIntegralView iMyIntegralView) {
        this.iMyIntegralView = iMyIntegralView;
    }

    @Background
    @Override
    public void getUserScore() {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/user/score",
                    iMyIntegralView.getToken(), new BaseView(iMyIntegralView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iMyIntegralView.userScoreSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iMyIntegralView
                                    .userScoreError(error);
                        }
                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iMyIntegralView.isResponseResult()) {
                iMyIntegralView
                        .userScoreError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }

}
